package cn.tedu._08security.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/")
public class ResourceController {
    /**
     * 测试资源: 不需要认证[登录]即可访问;
     */
    @GetMapping("public/hello")
    public String publicResource(){
        return "Hello public";
    }

    /**
     * 测试资源: 需要认证[登录]即可访问;
     * 拥有:sys:private:view权限的用户可以访问该资源;
     */
    @PreAuthorize("hasAuthority('sys:private:view')")
    @GetMapping("private/hello")
    public String privateResource(){
        return "Hello private";
    }
}
